//
//  VisitorView.swift
//  jackWu
//
//  Created by Lewhaming on 2016/11/22.
//  Copyright © 2016年 IQ. All rights reserved.
//

import UIKit
//protocol VisitorViewDelegate:NSObjectProtocol {
//    //默认要实现
//    func visitorViewDidClickLoginBtn(visitor:VisitorView)
//    
//    func visitorViewDidClickRegisterBtn(visitor:VisitorView)
//}

class VisitorView: UIView {
    
    @IBOutlet weak var iconView: UIImageView!

    @IBOutlet weak var textView: UILabel!
    
    @IBOutlet weak var rotationView: UIImageView!
    
    @IBOutlet weak var regButton: UIButton!

    @IBOutlet weak var loginButton: UIButton!
    // clas func +
    // func -
    
//    weak var delegate : VisitorViewDelegate?
    
    class func visitorView() -> VisitorView{
        return Bundle.main.loadNibNamed("VisitorView", owner: nil, options: nil)?.last as! VisitorView
    }
    //设置访客试图上的数据
    func setupVisitorInfo(imageName:String?, title:String){
        textView.text = title
        guard let name = imageName else {
            
            startAniamtion()
            return
        }
        rotationView.isHidden = true
        iconView.image = UIImage(named: name)
        
    }
    
    private func startAniamtion(){
        //创建动画
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = 2 * M_PI
        anim.duration = 8.0
        anim.repeatCount = MAXFLOAT
        anim.isRemovedOnCompletion = false
        
        rotationView.layer.add(anim, forKey: nil)
        
    }
    

}
